package com.mindbook.vip.gawxchatinfo.controller.nostrum;

import com.mindbook.vip.gawxchatinfo.entity.nostrum.NostrumType;
import com.mindbook.vip.gawxchatinfo.service.nostrum.NostrumTypeService;
import com.mindbook.vip.gawxchatinfo.utils.crud.CrudUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.Result;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @NAME: wxb
 * @DATE: 2022/6/19
 * @DESCRIPTION: 秘芳
 **/
@Api(value = "秘芳分类")
@RestController
@RequestMapping("nostrumType")
public class NostrumTypeController {

    @Autowired private NostrumTypeService nostrumTypeService;

    /**
     * 数据新增
     * @param nostrumType
     * @return
     */
    @PostMapping("/")
    @ApiOperation(value = "新增")
    private Result save(NostrumType nostrumType){
        Integer add = nostrumTypeService.saveByPrimaryKeySelective(nostrumType);

        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_ADD_SUCCESS.getMsg());
    }

    /**
     * 数据修改
     * @param nostrumType
     * @return
     */
    @PutMapping("/")
    @ApiOperation(value = "修改")
    private Result put(NostrumType nostrumType){
        Integer add = nostrumTypeService.put(nostrumType);

        CrudUtils.validateAddResult(add);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_UPDATE_SUCCESS.getMsg());
    }

    /**
     * 数据删除
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    private Result del(@PathVariable Integer id){
        Integer del = nostrumTypeService.removeByPrimaryKey(id);

        CrudUtils.validateDeleteResult(del);

        return ResultUtils.genSuccessResult(ResultEnum.DATA_DELETE_SUCCESS.getMsg());
    }

    @GetMapping("treeList")
    @ApiOperation(value = "tree型结构")
    private Result getTreeList(){

        List treeList = nostrumTypeService.getTreeList();

        return ResultUtils.genSuccessResult(treeList);
    }



}
